import dt from '@dt/dt'
import nameOpt from '@/biz/option/name.js'
import houseOpt from '@/biz/option/house.js'

function options(info, type = 0) {
  // 0 选择 1 弹框 2 明细
  let check =
    type == 1
      ? [
          {
            type: 'checkbox',
            minWidth: 50,
            fixed: 'left'
          }
        ]
      : []

  let handle =
    type == 0
      ? [
          {
            field: 'handles',
            title: '操作',
            width: 80,
            fixed: 'right',
            cell: {
              btn: [
                {
                  title: '删除',
                  event: 'onDelete'
                }
              ]
            }
          }
        ]
      : []

  return [
    ...check,
    {
      type: 'index',
      title: '序号',
      minWidth: 50,
      fixed: 'left'
    },
    {
      field: 'roomName',
      minWidth: 150,
      fixed: 'left',
      header: {
        filter: houseOpt.createRoom({
          key: 'roomId',
          title: '房源名称'
        })
      }
    },
    {
      field: 'commissionOrderStatusStr',
      minWidth: 100,
      title: '房源状态',
      header:
        type == 1
          ? null
          : {
              filter: {
                title: '房源状态',
                key: 'commissionOrderStatus',
                placeholder: '请选择房源状态',
                select: {
                  key: 'commissionOrderStatus'
                }
              }
            }
    },
    {
      field: 'contractDate',
      minWidth: 150,
      title: '签约日期',
      header:
        type == 1
          ? null
          : {
              filter: {
                title: '签约日期',
                key: 'contractDate',
                placeholder: '请选择签约日期',
                date: {
                  type: 'daterange'
                },
                data: {
                  to: (val) => {
                    return {
                      contractStartDate: val[0],
                      contractEndDate: val[1]
                    }
                  }
                }
              }
            }
    },
    {
      field: 'customerName',
      minWidth: 150,
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {}
        }
      }
    },
    {
      field: 'productName',
      title: '产品',
      minWidth: 150
    },
    {
      field: 'counselorName',
      minWidth: 100,
      header: {
        filter: nameOpt.create({
          key: 'counselorId',
          title: '签约人'
        })
      }
    },
    {
      field: 'channelSourceName',
      title: '渠道来源',
      minWidth: 120
    },
    {
      field: 'isAssociatesStr',
      minWidth: 100,
      header: {
        filter: {
          title: '关系户',
          key: 'isAssociates',
          placeholder: '请选择是否关系户',
          select: {
            options: [
              { key: 1, value: '是' },
              { key: 0, value: '否' }
            ]
          }
        }
      }
    },
    {
      field: 'isInsteadOfWorkersStr',
      minWidth: 100,
      header: {
        filter: {
          title: '联代分佣',
          key: 'isInsteadOfWorkers',
          placeholder: '请选择是否联代分佣',
          select: {
            options: [
              { key: 1, value: '是' },
              { key: 0, value: '否' }
            ]
          }
        }
      }
    },
    {
      field: 'area',
      title: '面积(m²)',
      minWidth: 100,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'unitPrice',
      title: '签约单价(元)',
      minWidth: 130,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'basicTotalPrice',
      title: '底总价(元)',
      minWidth: 100,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'totalPrice',
      title: '签约总价(元)',
      minWidth: 130,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'predictAccountDate',
      minWidth: 150,
      title: '全款到账日期',
      header:
        type == 1
          ? null
          : {
              filter: {
                title: '全款到账日期',
                key: 'predictAccountDate',
                placeholder: '请选择全款到账日期',
                date: {
                  type: 'daterange'
                },
                data: {
                  from: (info) => {
                    if (info.accountDateStart) {
                      return [info.accountDateStart, info.accountDateEnd]
                    }
                  },
                  to: (val) => {
                    return {
                      accountDateStart: val[0],
                      accountDateEnd: val[1]
                    }
                  }
                }
              }
            }
    },
    {
      field: 'accumulateMoney',
      title: '累计回款金额(元)',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'preSettlementAmount',
      title: '预计结算总销(元)',
      minWidth: 150,
      visible: info?.settlementType == 'STANDARD' || info?.settlementType == 'DEPOSIT',
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'preAgentCost',
      title: '预计结算代理费(元)',
      visible: info?.settlementType == 'STANDARD' || info?.settlementType == 'DEPOSIT',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'settlementAmount',
      title: '实际结算总销(元)',
      minWidth: 150,
      visible: type == 2,
      cell: {
        value: (row) =>
          info.status == 'SETTLED'
            ? row.settlementType == 'PREMIUM' && row.premiumTotalSale
              ? dt.tool.formatterMoney(row.premiumTotalSale)
              : row.settlementAmount
              ? dt.tool.formatterMoney(row.settlementAmount)
              : '-'
            : '-',
        text: {}
      }
    },
    {
      field: 'actualAgentCost',
      title: '实际结算代理费(元)',
      visible: type == 2,
      minWidth: 150,
      cell: {
        value: (row) =>
          info.status == 'SETTLED' && row.actualAgentCost ? dt.tool.formatterMoney(row.actualAgentCost) : '-',
        text: {}
      }
    },
    ...handle
  ]
}

export default {
  options
}
